<!--
 * @Author: licongwei
 * @Date: 2022-03-07 17:23:15
 * @FileDescription: 生产资料
-->
<template>
  <div class="P2">
    <div class="left box">
      <left-top
        @change="handPieChange"
        class="left-top box-top"
        ref="refLeftTop"
      ></left-top>
      <left-lower
        @change="handListChange"
        :classId="classId"
        class="left-lower box-lower"
        ref="refLeftLower"
      >
        <template #titleRight>
          <el-icon class="item-icon" @click="handIconClick('leftLower')">
            <ZoomIn />
          </el-icon>
        </template>
      </left-lower>
    </div>
    <div class="center box">
      <div class="center-top box-top">
        <div class="box-msg">
          <span class="msg-goodName">{{ goodsName }}</span>
        </div>
        <center-top :goodsId="goodsId" ref="refCenterTop">
          <template #titleRight>
            <el-icon
              class="item-icon centerTop"
              @click="handIconClick('centerTop')"
            >
              <ZoomIn />
            </el-icon>
          </template>
        </center-top>
      </div>
      <center-lower
        :goodsId="goodsId"
        :classId="classId"
        :goodsName="goodsName"
        class="center-lower box-lower"
        ref="refCenterLower"
      >
        <template #titleRight>
          <el-icon
            class="item-icon centerLower"
            @click="handIconClick('centerLower')"
          >
            <ZoomIn />
          </el-icon>
        </template>
      </center-lower>
    </div>
    <div class="right box">
      <right-top :goodsId="goodsId" class="right-top box-top" ref="refRightTop">
        <template #titleRight>
          <el-icon
            class="item-icon rightTop"
            @click="handIconClick('rightTop')"
          >
            <ZoomIn />
          </el-icon>
        </template>
      </right-top>
      <right-lower
        :goodsId="goodsId"
        class="right-lower box-lower box-top"
        ref="refRightLower"
      >
        <template #titleRight>
          <el-icon
            class="item-icon rightLower"
            @click="handIconClick('rightLower')"
          >
            <ZoomIn />
          </el-icon>
        </template>
      </right-lower>
      <!-- <right-lowerTwo
        :goodsId="goodsId"
        class="box-lower box-label"
        ref="refRightLowerTwo"
      ></right-lowerTwo> -->
    </div>
    <div class="enlarge">
      <!-- :style="{
          'z-index': iconText !== null ? 10 : -1,
          opacity: iconText !== null ? 1 : 0
        }" -->
      <enlarge-vue
        class="enlarge-nav"
        :style="
          isTransition
            ? { 'z-index': 999, opacity: 1 }
            : { 'z-index': 0, opacity: 0 }
        "
        @close="handIconClick('')"
      >
        <transition
          name="fade"
          :enter-from-class="transitionName"
          :leave-to-class="transitionName"
        >
          <component
            style="background-color: #001949"
            :is="iconText"
            :goodsIds="goodsId"
            :goodsId="goodsId"
            :goodsName="goodsName"
            :type="goodsName"
            :classId="classId"
          />
        </transition>
      </enlarge-vue>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, computed, watch } from 'vue'
import { useStore } from 'vuex'
import leftTop from './cpns/leftTop.vue'
import leftLower from './cpns/leftLower.vue'
import centerTop from './cpns/centerTop.vue'
import centerLower from './cpns/centerLower.vue'
import rightTop from './cpns/rightTop.vue'
import rightLower from './cpns/rightLower.vue'
import rightLowerTwo from './cpns/rightLowerTwo.vue'
import { ZoomIn } from '@element-plus/icons-vue'
import enlargeVue from './cpns/enlarge.vue'
import leftLowerModal from './cpns/modal/leftLower.vue'
import rightTopModal from './cpns/modal/rightTop.vue'
import rightLowerModal from './cpns/modal/rightLower.vue'
import centerTopModal from './cpns/modal/centerTop.vue'
import centerLowerModal from './cpns/modal/centerLower.vue'
export default defineComponent({
  name: 'M6',
  components: {
    leftTop,
    leftLower,
    centerTop,
    centerLower,
    rightTop,
    rightLower,
    rightLowerTwo,
    enlargeVue,
    ZoomIn,
    leftLowerModal,
    rightTopModal,
    rightLowerModal,
    centerTopModal,
    centerLowerModal
  },
  setup() {
    const classId = ref('')
    const goodsId = ref('')
    const goodsName = ref('')
    const refLeftTop = ref()
    const refLeftLower = ref()
    const refCenterTop = ref()
    const refCenterLower = ref()
    const refRightTop = ref()
    const refRightLower = ref()
    const refRightLowerTwo = ref()
    const store = useStore()
    const handPieChange = (id: string) => {
      classId.value = id
    }
    const handListChange = (id: string, name: string) => {
      goodsId.value = id
      goodsName.value = name
    }
    const watchedState = computed(() => Object.values(store.state.globalDate))
    watch(watchedState, () => {
      refLeftTop.value?.refreshData()
      refLeftLower.value?.refreshData()
      refCenterTop.value?.refreshData()
      refCenterLower.value?.refreshData()
      refRightTop.value?.refreshData()
      refRightLower.value?.refreshData()
      refRightLowerTwo.value?.refreshData()
      // leftLowRef.value?.refreshData()
      // jgzsRef.value?.refreshData()
    })

    //    const refreshData = () => {
    //   state.getData(props.adcode, props.goodsIds)
    // }
    //    onBeforeUnmount(() => {
    //   clearInterval(state.timer)
    // })
    const isTransition = ref(false)
    const transitionName = ref('')
    const iconText: any = ref('')
    const handIconClick = (str: any) => {
      let bool = true
      switch (str) {
        case 'leftLower':
          transitionName.value = 'leftLow-transition'
          iconText.value = leftLowerModal
          break
        case 'rightTop':
          transitionName.value = 'rightTop-transition'
          iconText.value = rightTopModal
          break
        case 'rightLower':
          transitionName.value = 'rightLower-transition'
          iconText.value = rightLowerModal
          break
        case 'centerTop':
          transitionName.value = 'centerTop-transition'
          iconText.value = centerTopModal
          break
        case 'centerLower':
          transitionName.value = 'centerLower-transition'
          iconText.value = centerLowerModal
          break
        default:
          bool = false
          iconText.value = ''
          break
      }
      store.commit('setScroll', bool)
      if (bool) {
        isTransition.value = true
      }
    }
    watch(iconText, (newVal: any) => {
      if (newVal == '') {
        setTimeout(() => {
          isTransition.value = false
        }, 250)
      } else {
        isTransition.value = true
      }
    })
    return {
      handListChange,
      handPieChange,
      handIconClick,
      classId,
      goodsName,
      goodsId,
      refLeftTop,
      refLeftLower,
      refCenterTop,
      refCenterLower,
      refRightTop,
      refRightLower,
      refRightLowerTwo,
      isTransition,
      transitionName,
      iconText
    }
  }
})
</script>
<style lang="less" scoped>
.P2 {
  display: flex;
  color: #fff;
  .item-icon {
    cursor: pointer;
    z-index: 2;
    font-size: 25px;
    margin-top: 12px;
    margin-left: 78px;
    &:hover {
      color: rgba(255, 255, 255, 0.5);
    }
    &.rightTop {
      margin-left: 138px;
    }
    &.rightLower {
      margin-left: 138px;
    }
    &.centerTop {
      margin-left: 188px;
    }
    &.centerLower {
      margin-left: 188px;
    }
  }
  .left {
    display: flex;
    flex: 0 0 500px;
    margin-right: 7px;
  }
  .center {
    display: flex;
    flex: 1;
    margin: 0px 7px;
  }
  .right {
    display: flex;
    flex: 0 0 620px;
    margin-left: 7px;
  }
}
.box {
  display: flex;
  flex-direction: column;
  .left-top {
    flex: 0 0 370px;
  }
  .left-lower {
    flex: 1;
  }
  .center-top {
    height: 50%;
    position: relative;
    .box-msg {
      // background-color: #f0f;
      display: flex;
      justify-content: center;
      align-items: center;
      position: absolute;
      width: 200px;
      height: 60px;
      top: 4px;
      left: 8px;
      z-index: 99;
      font-size: 22px;
      color: #fdd931;
      line-height: 30px;
      text-align: center;
      span {
        font-family: 'AliHYAiHei';
      }
    }
  }
  .center-lower {
    height: 50%;
  }
  .right-top {
    flex: 0 0 380px;
  }
  .right-lower {
    flex: 1;
  }
  .box-label {
    flex: 0 0 245px;
  }
  .box-top {
    margin-bottom: 7px;
  }
  .box-lower {
    margin-top: 7px;
  }
  .enlarge-nav {
    float: left;
  }
  //进入过度
  .fade-enter-active,
  .fade-leave-active {
    transition: all 0.3s;
  }
  //·进入完成
  .fade-enter-to,
  .fade-leave-from {
    transform: translate3d(0px, 0px, 0px) scale(1);
  }

  // 左上角
  // .leftTop-transition {
  //   transform: translate3d(-676px, -126px, 0) scale(0.7);
  // }
  // 重要商品价格
  .leftLow-transition {
    transform: translate3d(-659px, 325px, 0) scale(0.65);
  }
  // 右上角
  .rightTop-transition {
    transform: translate3d(696px, -234px, 0) scale(0.7);
  }
  // 右下角
  .rightLower-transition {
    transform: translate3d(696px, 91px, 0) scale(0.7);
  }
  // 中间顶部
  .centerTop-transition {
    transform: translate3d(0, -234px, 0) scale(0.7);
  }
  // 中间底部
  .centerLower-transition {
    transform: translate3d(0, 91px, 0) scale(0.7);
  }
  // 地图
  .map-transition {
    transform: translate3d(17px, -31px, 0) scale(0.8);
  }
  // 周边省份价格对比
  .cR36dzcs-transition {
    transform: translate3d(696px, -234px, 0) scale(0.7);
  }
  // 国内外数据对比
  .jgzs-transition {
    transform: translate3d(696px, 91px, 0) scale(0.7);
  }
}
</style>
